class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ parts = path.split("/") result = [''] for part in parts: if part: if part not in ('.', '..'): if len(result) == 0: # 若栈底空了,加入空字符再加入目录名 result.append('') result.append(part) elif part == '..' and len(result) > 0: result.pop() if len(result) < 2: return "/" else: return "/".join(result) # 以/来组合list里的字符